package org.cnbi.utils.pojo;

import java.util.HashMap;
import java.util.Map;

import org.cnbi.utils.date.DateUtil;
import org.cnbi.utils.json.JsonUtil;
import org.cnbi.utils.string.StringUtil;
import org.cnbi.utils.tools.GlobalConstants;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;

public class SqlParamsBean {

	private Integer unit = 1;
	/**
	 * 数据缓存键
	 */

	@JsonIgnore
	private String cacheKey;
	@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
	@JsonIgnore
	private String period ;
	
	@JsonIgnore
	private String company = "1";
	
	@JsonIgnore
	private String season = "1";
	

	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private String year = "2013";

	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private String month = "03";
	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private Map<String, String> conditionMap = new HashMap<String, String>();
	

	@JsonIgnore
	/**
	 * 相对期间
	 */
	private String relativeperiod;
	/**
	 * 维度名称 只有它的值可以是字母
	 */
	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private String[] dimarr;
	/**
	 * 查询度量
	 */
	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private String[] queryfact = new String[] { "A", "B", "C", "D", "E" };
	/**
	 * 查询主题
	 */
	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private String subject = GlobalConstants.PERIOD_SUBJECT;

	private String[] showdim = new String[] { "Item" };

	

	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private String sqlkey;

	public SqlParamsBean() {
	}

	/**
	 * @param cacheKey the cacheKey to set
	 */
	public void setCacheKey(String cacheKey) {
		this.cacheKey = cacheKey;
	}
	/**
	 * @param return the cacheKey 
	 */
	public String getCacheKey(){
		String cacheKey =  JsonUtil.generateJson(this);
		cacheKey = StringUtil.getAllNumber(cacheKey);
		//cacheKey = this.company+this.year+this.month+this.unit;
	    System.out.println("SqlParamsBean.getCacheKey()========"+cacheKey);
		return cacheKey;
	}
	
	/**
	 * @return the conditionMap
	 */
	public Map<String, String> getConditionMap() {
		  conditionMap.put("period",getPeriod());
		  conditionMap.put("company", getCompany());
		return conditionMap;
	}

	/**
	 * @param conditionMap the conditionMap to set
	 */
	public void setConditionMap(Map<String, String> conditionMap) {
		 
		  this.conditionMap = conditionMap;
	}
	/**
	 * @return the period
	 */
	public String getPeriod() {
		if (null == this.period){
			this.period = this.year + this.month;
		}
		return period;
	}

	/**
	 * @return the relativeperiod
	 */
	public String getRelativeperiod() {
		return DateUtil.getRelativePeriod("-1&0", getPeriod());
	}

	/**
	 * @param relativeperiod
	 *            the relativeperiod to set
	 */
	public void setRelativeperiod(String relativeperiod) {
		this.relativeperiod = relativeperiod;
	}

	

	/**
	 * @param period
	 *            the period to set
	 */
	public void setPeriod(String period){
		this.period = period;
	}

	/**
	 * @return the year
	 */
	public String getYear() {
		if (null == this.year && null != this.period) {
			this.year = this.period.substring(0, 4);
		}
		return year;
	}

	/**
	 * @param year
	 *            the year to set
	 */
	public void setYear(String year) {
		this.year = year;
	}

	/**
	 * @return the month
	 */
	public String getMonth() {
		if (null == this.month && null != this.period) {
			this.month = this.period.substring(4, 6);
		}
		return month;
	}

	/**
	 * @return the unit
	 */

	/**
	 * @param unit
	 *            the unit to set
	 */
	public void setUnit(Integer unit) {
		this.unit = unit;
	}

	public Integer getUnit() {// 1=元 2=千元 3=万元 4=亿元
		return unit;
	}

	/**
	 * @return the dimarr
	 */
	public String[] getDimarr() {
		return dimarr;
	}

	/**
	 * @param dimarr
	 *            the dimarr to set
	 */
	public void setDimarr(String[] dimarr) {
		this.dimarr = dimarr;
	}

	/**
	 * @return the queryfact
	 */
	public String[] getQueryfact() {
		return queryfact;
	}

	/**
	 * @param queryfact
	 *            the queryfact to set
	 */
	public void setQueryfact(String[] queryfact) {
		this.queryfact = queryfact;
	}

	/**
	 * @return the subject
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * @param subject
	 *            the subject to set
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}

	

	/**
	 * @return the showdim
	 */
	public String[] getShowdim() {
		return showdim;
	}

	/**
	 * @param showdim the showdim to set
	 */
	public void setShowdim(String[] showdim) {
		this.showdim = showdim;
	}

	/**
	 * @return the sqlkey
	 */
	public String getSqlkey() {
		return sqlkey;
	}

	/**
	 * @param sqlkey
	 *            the sqlkey to set
	 */
	public void setSqlkey(String sqlkey) {
		this.sqlkey = sqlkey;
	}

	/**
	 * @param month
	 *            the month to set
	 */
	public void setMonth(String month) {
		this.month = month;
	}

	
	/**
	 * @return the company
	 */
	public String getCompany() {
		return company;
	}

	/**
	 * @param company the company to set
	 */
	public void setCompany(String company) {
		this.company = company;
	}

	/**
	 * @return the season
	 */
	public String getSeason() {
		return season;
	}

	/**
	 * @param season the season to set
	 */
	public void setSeason(String season) {
		this.season = season;
	}
	
	

}
